<extend name="Base/common" />
<block name="body">
	<!--导航引用-->
	<include file="Public/nav" />
	<footer class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
		<input type="hidden" id="id" value="{$row.id|default=0}" />
		<input type="hidden" id="prevurl" value="{$row.prevurl|default='no'}">
	    <button class="ui-btn bt_rtext save_bank">保存</button>
	</footer>
	<section class="ui-container">
		<div class="ui-add-address-from">
			<div class="ui-form-item ui-border-b">
	            <label class="ui-border-r">开户姓名:</label>
	            <input type="text" placeholder="开户姓名" value="{$row.open_name|default=''}" name="open_name" id="open_name">
	            </a>
	        </div>
	        <div class="ui-form-item ui-border-b">
	            <label class="ui-border-r">开户银行:</label>
	            <div class="ui-select">
	                <select id="open_bank_name" name="open_bank_name">
	                    <option value="-1">请选择...</option>
						<volist name="list_bank" id="v">
		            		<option value="{$v.name}" <if condition="$v['name'] eq $row['open_bank_name']">selected="selected"</if>>{$v.name}</option>
		            	</volist>
	                </select>
	            </div>
	        </div>
	        <div class="ui-form-item ui-border-b">
	            <label class="ui-border-r">银行卡号:</label>
	            <input type="text" placeholder="银行卡号" value="{$row.bank_account|default=''}" name="bank_account" id="bank_account">
	        </div>
		</div>
	</section>
</block>
<block name="script">
	<script type="text/javascript">
		$('.save_bank').tap(function(){

			var name = $('#open_name').val(),
				account = $('#bank_account').val(),
				open_bank_name = $('#open_bank_name').val(),
				prevurl = $('#prevurl').val();

			if(name.length == 0){
				$.tips({content:'开户姓名不能为空！',stayTime:2000,type:"success"});
				return false;
			}
			if(account.length == 0){
				$.tips({content:'开户银行不能为空！',stayTime:2000,type:"success"});
				return false;
			}

			if(open_bank_name == -1){
				$.tips({content:'银行卡号不能为空！',stayTime:2000,type:"success"});
				return false;
			}

			var el = '';
			$.ajax({
				url: "{:U('Member/update_bank')}",
				type: 'POST',
				data: {open_name: name, bank_account: account, open_bank_name: open_bank_name, prevurl: prevurl},
				dataType: 'json',
				beforeSend: function(){
					el = $.loading({content:'加载中...'})
				},
				success: function(r){
					el.loading("hide");
					if (r.status) {
						$.tips({
					        content:'添加成功',
					        stayTime:2000,
					        type:"success"
					    });
					    window.location.href=r.url;
					} else {
						$.tips({
					        content:'添加失败',
					        stayTime:2000,
					        type:"success"
					    });
					}
				}
			});
		});
	</script>
</block>
